

/*当ie版本低于IE9时，复选框选中效果*/
$(function() {
  var browser = navigator.appName;
  var b_version = navigator.appVersion;
  var version = b_version.split(";");
  var trim_Version ="";
  if(version.length>1){
      trim_Version = version[1].replace(/[ ]/g, ""); 
  }
  if (browser == "Microsoft Internet Explorer" && trim_Version == "MSIE8.0") {
    $('.checkbox label').hide();
    $('.checkbox input').show();
  }
    
});

/*批量导入*/
function bulkImport(){
    var file = $('#file'),
    fileName = $('.fileName');
    file.on('change', function( e ){
        //e.currentTarget.files 是一个数组，如果支持多个文件，则需要遍历
        var name = e.currentTarget.files[0].name;
        fileName.text(name);
    });
}

/*编辑用户*/
function editUser(){
    $("body").on("click",".edit-user",function(){
        var phone = $(this).parents("tr").children("td").eq(4).text();
        var email = $(this).parents("tr").children("td").eq(5).text();
        var used = $(this).parents("tr").children("td").eq(6).text();
        $(".phone").text(phone);
        $(".email").text(email);
        if(used=="启用"){
            $(".start-radio").prop("checked",true);
        }else{
            $(".stop-radio").prop("checked",true);
        }
    })
}


/*执行*/
$(function() {

    /*新增用户*/
    win(".add-user-btn",".win-add-user",".btn");

    /*编辑用户*/
    win(".edit-user",".win-edit-user",".btn");
    editUser();

    /*批量导入*/
    win(".import-btn",".win-import",".btn");
    bulkImport();

    /*删除用户*/
    win(".delete-user",".win-delete",".btn");

    /*批量操作*/
    $('.operation-btn').on('click', function() {
        $('.user-list .checkbox, #opBtmBtns').show();
    });
    $('#opBtmBtns .btn-quit').click(function(){
        $('.user-list .checkbox, #opBtmBtns').hide();
    });
    $.MyCheckbox('.user-list', '#checked-num');
    $('#opBtmBtns .btn-delete').click(function(){
        var count = $('#checked-num').text();
        if (!count) {
            $('.win-check').show();
        } else {
            $('.win-delete').show();
        }
    });
    $('.btn-close').click(function() {
        $('.win').hide();
    })
});